<?php

if(isset($_GET['vimage'])){
        $check_url = (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['SCRIPT_NAME']);
        if (eregi("index.php", $check_url) && preg_match("/^[0-9a-z]{32}$/", $_GET['vimage'])){
                $vres = dbquery("SELECT * FROM ".$db_pref."vcode WHERE vcode_2='".quote_real_escape_string($_GET['vimage'])."'");
                if (dbrows($vres)){
                        $vdata = dbarray($vres);


                        $imf = rand(3,5); $imx = rand(15,40); $imy = rand(2,7);
                        $im = ImageCreateFromJPEG("./images/validate_bg.jpg");
                        $tcolor = ImageColorAllocate($im, 40, 40, 40);

                        $height = 32;
                        $width = 72;

                        $count_symbol=strlen($vdata["vcode_1"]);
                        $count_space=floor($width/$count_symbol);


                        $array_param=array();
                        $array_text=array();
                        $x_pos_gl=0; $x_pos_st=0;
                        for($i=0; $i<$count_symbol; $i++){
                                $x_pos=$i*($count_space) + rand(2, 8);
                                if($i==0){
                                        $x_pos_st=$x_pos;
                                }elseif($i==($count_symbol-1)){
                                        $x_pos_gl=$x_pos;
                                }
                                $array_param[$i]=$x_pos;
                                $array_text[$i] = $vdata["vcode_1"][$i];
                        }
                        $x_pos_gl=$x_pos_gl+16;
                        $x_pos_sdvig=floor(($width-($x_pos_gl-$x_pos_st))/2);

                        $x_pos_sdvig=floor(($width-($count_symbol*8))/2);

                        $str_color = imagecolorallocate($im, 10, 10, 10);
                        $y=rand(2, 8);
                        for($i=0; $i<count($array_param); $i++){
                                $sz = rand(10, 12);
                                $x_pos = $array_param[$i]+$x_pos_sdvig;

                                //ImageString ($im, $sz, ($i*$count_space), $y, $array_text[$i], $str_color);
                                //$key_str_array = imagettftext($im, $sz, rand(-10, 10), $x_pos, rand(16, 20), $str_color, "verdana", $array_text[$i]);
                        }
                                //ImageString ($im, $sz, $x_pos_sdvig+25, $y, $vdata["vcode_1"], $str_color);
                                $sz = rand(12, 14);
                                imagettftext($im, $sz, rand(-8, 8), $x_pos_sdvig, rand(16, 24), $str_color, "./res/fonts/Copyviol.ttf", $vdata["vcode_1"]);

                                Header("Content-type: image/jpeg");
                                ImageJPEG($im, '', 80);
                                ImageDestroy($im);

                }
        }
        die();
        break;
}


?>